﻿package client;

import java.awt.BorderLayout;
import java.awt.EventQueue;

import javax.swing.JFrame;
import javax.swing.JPanel;
import javax.swing.border.EmptyBorder;
import javax.swing.JDialog;
import javax.swing.JOptionPane;
import javax.swing.JTree;
import javax.swing.JTabbedPane;
import javax.swing.JLabel;
import javax.swing.JComboBox;
import javax.swing.JTable;
import javax.swing.JScrollPane;
import javax.swing.JButton;
import javax.swing.table.DefaultTableModel;
import java.awt.event.ActionListener;
import java.awt.event.ActionEvent;
import java.net.MalformedURLException;
//import java.rmi.Naming;
import java.rmi.Naming;
import java.rmi.NotBoundException;
import java.rmi.RemoteException;
import java.sql.SQLException;
import java.text.ParseException;
import java.text.SimpleDateFormat;
import java.util.ArrayList;
import java.util.Date;

import java.util.Vector;
import client.Configuration;
import server.ResBookInterface;
import server.ResDinnerInterface;
import server.ResTableInterface;
import server.ResTakeOutInterface;
import server.ResStaffInterface;
import server.ResWaiterInterface;

import java.awt.event.MouseAdapter;
import java.awt.event.MouseEvent;
import javax.swing.ImageIcon;

public class ResManageGUI extends JDialog {

	private JPanel contentPane;
	private JTable table;
	private JTable table_1;
	private JTable table_2;
	private JTable table_3;
	private JTable table_4;
	
	private DefaultTableModel   dtm;  
	//private String datee;
	private JComboBox comboBox ;
	private JTable table_5;


	private int ii;

	
	
	ArrayList<Vector> info1=new ArrayList<Vector>();
	ArrayList<Vector> info2=new ArrayList<Vector>();
	ArrayList<Vector> info3=new ArrayList<Vector>();

	
	ArrayList<Vector> staff1=new ArrayList<Vector>();
	ArrayList<Vector> staff2=new ArrayList<Vector>();


	ArrayList<Vector> table1=new ArrayList<Vector>();

	
	
	
	
	private ResWaiterInterface waiter;
	private ResTableInterface tabl;
	
	
	
	private JScrollPane scrollPane;
	private JScrollPane scrollPane_2;
	private JScrollPane scrollPane_1;
	
	DefaultTableModel model5;
	/**
	 * Launch the application.
	*/
	public static void main(String[] args) {
		EventQueue.invokeLater(new Runnable() {
			public void run() {
				try {
					ResManageGUI frame = new ResManageGUI();
					frame.setVisible(true);
				} catch (Exception e) {
					e.printStackTrace();
				}
			}
		});
	}
 
	/**
	 * Create the frame.
	 * @throws NotBoundException 
	 * @throws RemoteException 
	 * @throws MalformedURLException 
	 */
	public ResManageGUI() throws MalformedURLException, RemoteException, NotBoundException {
		setDefaultCloseOperation(JDialog.DISPOSE_ON_CLOSE);
		setBounds(100, 100, 687, 492);
		contentPane = new JPanel();
		contentPane.setBorder(new EmptyBorder(5, 5, 5, 5));
		setContentPane(contentPane);
		contentPane.setLayout(null);
		
		JTabbedPane tabbedPane = new JTabbedPane(JTabbedPane.LEFT);
		tabbedPane.setBounds(10, 10, 651, 434);
		contentPane.add(tabbedPane);
		
		JPanel panel = new JPanel();
		tabbedPane.addTab("\u8BB0\u5F55\u67E5\u8BE2", null, panel, null);
		panel.setLayout(null);
		
		//////////////////////////////////////////111
		
		SimpleDateFormat sdf=new SimpleDateFormat("yyyy-MM-dd");
		Date date=new Date();
		
		String[] Days=new String[20];
		Days[0]=sdf.format(date);
		for(int i=1;i<=19;i++)
		{
			date.setTime(date.getTime() + 1* 24 * 60
				* 60 * 1000);

	    	Days[i]=sdf.format(date);
		}
		
//	datee=new String();
		
		comboBox = new JComboBox(Days);
		comboBox.addActionListener(new ActionListener() {
			public void actionPerformed(ActionEvent e) {
				
		
			}
		});
		
	//	System.out.print(datee);
		comboBox.setBounds(253, 10, 132, 25);
		panel.add(comboBox);
		
	//	datee=(String) comboBox.getSelectedItem();



	
	    

		
		
		///////////////////////
		
		JTabbedPane tabbedPane_1 = new JTabbedPane(JTabbedPane.TOP);
		tabbedPane_1.setBounds(0, 38, 558, 391);
		panel.add(tabbedPane_1);
		
		 scrollPane = new JScrollPane();
		tabbedPane_1.addTab("\u7528\u9910\u4FE1\u606F\u8BB0\u5F55", null, scrollPane, null);
		
		
		
		Configuration config=new Configuration();
		String rmiAddress=config.getRmiAddress();
		
		final ResBookInterface book = (ResBookInterface) Naming.lookup(rmiAddress+"ResBookInfo");
		final ResDinnerInterface dinner = (ResDinnerInterface) Naming.lookup(rmiAddress+"ResDinnerInfo");
		final ResTakeOutInterface takeOut = (ResTakeOutInterface) Naming.lookup(rmiAddress+"ResTakeOutInfo");
		
		tabl=(ResTableInterface)Naming.lookup(rmiAddress+"ResTable");
			
		
		
		scrollPane_1 = new JScrollPane();
		tabbedPane_1.addTab("\u5916\u5356\u4FE1\u606F\u8BB0\u5F55", null, scrollPane_1, null);
		
	
		
		
		scrollPane_2 = new JScrollPane();
		tabbedPane_1.addTab("\u9884\u8BA2\u4FE1\u606F\u8BB0\u5F55", null, scrollPane_2, null);
	
		JLabel label = new JLabel("\u8BF7\u9009\u62E9\u67E5\u8BE2\u65E5\u671F\uFF1A");
		label.setBounds(141, 10, 102, 25);
		panel.add(label);
	
		
		

		
		
		JButton button_3 = new JButton("\u67E5\u8BE2");
		button_3.addMouseListener(new MouseAdapter() {
			@Override
			public void mouseClicked(MouseEvent e) {
				
			}
		});
		button_3.addActionListener(new ActionListener() {
			public void actionPerformed(ActionEvent e) {
				
				int select=comboBox.getSelectedIndex();

			    Date day =new Date();
			    day.setTime(day.getTime()+select*24*60*60*1000);
				
			    
			    
			    
			///////////////////////////**********************
			    ////////////////333333333333333333333333
try {
				int m_1;
				
					m_1 = book.getFirstOrderNumber(day);
				
				int n_1=book.getBookSize(day);
			
				
				Vector<String> infobook;

	//			int []a=book.getAllBookNum();
				String f1,f2,f3,f4,f5;
				for(int i=m_1;i<n_1+m_1;i++){
					infobook=new Vector();
					f1=String.valueOf(i);					
					f2=book.getName(i);			
					f3=String.valueOf(book.getNumOfPeo(i));
					f4=book.getPhone(i);
					//f5=book.getOrderDate(i);
					f5=book.getBookDate(i);
					infobook.add(f1);
					infobook.add(f2);
					infobook.add(f3);
					infobook.add(f4);
					infobook.add(f5);
				//	infobook.add(f6);
					info1.add(infobook);
				}
			    
			    
			    
			    
			    //////////////////////////////222222222222222222222
				int m=dinner.getFirstDinnerNumber(day);
				int n = dinner.getDinnerSize(day);
			
				
				Vector<String> infodinner;

				String d1,d2,d3,d4,d5,d6;
				for(int i=m;i<n+m;i++){
					infodinner=new Vector();
					d1=String.valueOf(i);					
					d2=String.valueOf(dinner.getDinnerTable(i));			
					d3=String.valueOf(dinner.getDinnerPeople(i));
					d4=String.valueOf(dinner.getDinnerWaiter(i));
					d5=String.valueOf(dinner.getDinnerAmount(i));
					d6=dinner.getDinnerDate(i);
					infodinner.add(d1);
					infodinner.add(d2);
					infodinner.add(d3);
					infodinner.add(d4);
					infodinner.add(d5);
					infodinner.add(d6);
					info2.add(infodinner);
				}
			    //////////////1111111111111111111111111111
			    
				int m_2=takeOut.getFirstTakeOutNum(day);
				int n_2=takeOut.getTakeOutSize(day);
				
				
				Vector<String> infotake;

				String o1,o2,o3,o4,o5,o6;
				for(int i=m_2;i<n_2+m_2;i++){
					infotake=new Vector();
					o1=String.valueOf(i);					
					o2=takeOut.getCusName(i);			
					o3=takeOut.getPhone(i);
					o4=takeOut.getAddress(i);
					o5=String.valueOf(takeOut.getAmount(i));
					o6=takeOut.getDate(i);
					infotake.add(o1);
					infotake.add(o2);
					infotake.add(o3);
					infotake.add(o4);
					infotake.add(o5);
					infotake.add(o6);
					info3.add(infotake);
				}
				
				} catch (RemoteException e1) {
					// TODO Auto-generated catch block
					e1.printStackTrace();
				}
			    
//////////////////////////1111111111111111111111111			    
			    DefaultTableModel  Model3 = new DefaultTableModel(
						new Object[0][6],
						new String[] {
								"\u5916\u5356\u5355\u53F7", "\u59D3\u540D", "\u7535\u8BDD", "\u5730\u5740", "\u6D88\u8D39\u91D1\u989D", "\u65E5\u671F"
							}
						
						);
				for(int i=0;i<info3.size();i++)
					Model3.addRow(info3.get(i));

	    table_1=new JTable(Model3);

	    scrollPane_1.setViewportView(table_1);
	    
	    
	    
	    
	    //////////////////////222222222222222222222
		 DefaultTableModel  Model2 = new DefaultTableModel(
					new Object[0][6],
					new String[] {
							 
							"\u7528\u9910\u5355\u53F7", "\u684C\u53F7", "用餐人数","\u670D\u52A1\u5458 \u5DE5\u53F7", "\u6D88\u8D39\u91D1\u989D", "\u65F6\u95F4"
						}
					
					);
			for(int i=0;i<info2.size();i++)
					Model2.addRow(info2.get(i));

        table=new JTable(Model2);

		scrollPane.setViewportView(table);
		
		
		////////////////////////33333333333333333333333

		DefaultTableModel  Model1 = new DefaultTableModel(
					new Object[0][5],
					new String[] {
							"\u8BA2\u5355\u53F7","\u59D3\u540D" ,"\u4EBA\u6570",  "\u7535\u8BDD", "\u5403\u996D\u65E5\u671F"
						}
					
					);
			for(int i=0;i<info1.size();i++)
				Model1.addRow(info1.get(i));

			table_2=new JTable(Model1);
				
			scrollPane_2.setViewportView(table_2);	
					
				
			}
		});
		button_3.setBounds(432, 11, 93, 23);
		panel.add(button_3);
		///////////////////

		
		JPanel panel_1 = new JPanel();
		tabbedPane.addTab("\u5458\u5DE5\u4FE1\u606F\u67E5\u8BE2", null, panel_1, null);
		panel_1.setLayout(null);
		
		JTabbedPane tabbedPane_2 = new JTabbedPane(JTabbedPane.TOP);
		tabbedPane_2.setBounds(10, 20, 538, 409);
		panel_1.add(tabbedPane_2);
		
		JPanel panel_3 = new JPanel();
		tabbedPane_2.addTab("\u670D\u52A1\u5458", null, panel_3, null);
		panel_3.setLayout(null);

		
		JScrollPane scrollPane_3 = new JScrollPane();
		scrollPane_3.setBounds(10, 43, 513, 327);
		panel_3.add(scrollPane_3);
		
		
		
		ResStaffInterface staff = (ResStaffInterface) Naming.lookup(rmiAddress+"ResStaffList");
		
		
		
		
		
		int t_1=staff.getStaffNumber(1);
		int Waiter=staff.getFirstStaff(1);
		
		System.out.print(t_1);
		
		Vector<String> wai;

		String st1,st2,st3,st4,st5;
		for(int i=0;i<t_1;i++){
			wai=new Vector();
			st1=String.valueOf(Waiter);					
			st2=staff.getName(Waiter);			
			st3=String.valueOf(staff.getSex(Waiter));
			st4=String.valueOf(staff.getAge(Waiter));
			st5=String.valueOf(staff.getSalary(Waiter));
			
			wai.add(st1);
			wai.add(st2);
			wai.add(st3);
			wai.add(st4);
			wai.add(st5);

			staff1.add(wai);
			Waiter=staff.getNextStaffNum(1, Waiter);
		}
		
		
		
		int t_2=staff.getStaffNumber(2);
		int cook=staff.getFirstStaff(2);
		
		
		Vector<String> coo;

		String c1,c2,c3,c4,c5;
		for(int i=0;i<t_2;i++){
			coo=new Vector();
			c1=String.valueOf(cook);					
			c2=staff.getName(cook);			
			c3=String.valueOf(staff.getSex(cook));
			c4=String.valueOf(staff.getAge(cook));
			c5=String.valueOf(staff.getSalary(cook));
			
			coo.add(c1);
			coo.add(c2);
			coo.add(c3);
			coo.add(c4);
			coo.add(c5);

			staff2.add(coo);
			cook=staff.getNextStaffNum(2, cook);
		}
		
		
		
	
		
		DefaultTableModel mod1=new DefaultTableModel(
				new String[0][5],
				new String[] {
					"\u5458\u5DE5\u53F7", "\u59D3\u540D", "\u6027\u522B", "\u5E74\u9F84", "\u5DE5\u8D44"
				}
			);
		table_3 = new JTable(mod1);

		for(int i=0;i<staff1.size();i++)
			mod1.addRow(staff1.get(i));
		
		scrollPane_3.setViewportView(table_3);
		
		JLabel lblNewLabel_1 = new JLabel("1为女，2为男");
		lblNewLabel_1.setBounds(91, 14, 93, 15);
		panel_3.add(lblNewLabel_1);
		
		
		JPanel panel_4 = new JPanel();
		tabbedPane_2.addTab("\u53A8\u5E08", null, panel_4, null);
		panel_4.setLayout(null);
		
	/*	JButton button_1 = new JButton("\u89E3\u96C7");
		button_1.addActionListener(new ActionListener() {
			public void actionPerformed(ActionEvent e) {
			}
		});
		button_1.setBounds(407, 10, 93, 23);
		panel_4.add(button_1);		
	*/	
			JScrollPane scrollPane_4 = new JScrollPane();
		scrollPane_4.setBounds(10, 49, 513, 321);
		panel_4.add(scrollPane_4);	
		
		
		DefaultTableModel mod2=new DefaultTableModel(	
				new String[0][5],
			new String[] {
				"\u5458\u5DE5\u53F7", "\u59D3\u540D", "\u6027\u522B", "\u5E74\u9F84", "\u5DE5\u8D44"
			}
		);
		table_4=new JTable(mod2);
		
		for(int i=0;i<staff2.size();i++)
			mod2.addRow(staff2.get(i));
		
		scrollPane_4.setViewportView(table_4);
		
		

		
/*		JButton btnNewButton_1 = new JButton("\u89E3\u96C7");
		btnNewButton_1.addActionListener(new ActionListener() {
			public void actionPerformed(ActionEvent e) {
				int row=table_3.getSelectedRow();
				table_3.remove(row);
				staff1.remove(row);
				
			}
		});
		btnNewButton_1.setBounds(398, 10, 93, 23);
	panel_3.add(btnNewButton_1);

*/		
	
		
		JPanel panel_2 = new JPanel();
		tabbedPane.addTab("\u9910\u684C\u4FE1\u606F", null, panel_2, null);
		panel_2.setLayout(null);
		
		JScrollPane scrollPane_5 = new JScrollPane();
		scrollPane_5.setBounds(10, 51, 538, 368);
		panel_2.add(scrollPane_5);
		
		int n5=tabl.getTableListSize();

		
		
		Vector<String> tab;

		String ta1,ta2;
		for(int i=0;i<n5;i++){
			tab=new Vector();
			ta1=String.valueOf(i+1);					
			ta2=String.valueOf(tabl.getTableSize(i+1))	;		

			tab.add(ta1);
			tab.add(ta2);

			table1.add(tab);
		}
		
		
		table_5 = new JTable();
		
		model5=new DefaultTableModel(
				new String[0][2],
				new String[] {
					"\u684C\u53F7", "\u5BB9\u91CF"
				}
			);
		table_5.setModel(model5);
		for(int i=0;i<table1.size();i++)
			model5.addRow(table1.get(i));
		
		scrollPane_5.setViewportView(table_5);
		
		
		 waiter = (ResWaiterInterface) Naming.lookup(rmiAddress+"ResWaiter");
		 
		 //////////////////zhuozizhuozizhuozi
		
		JButton btnNewButton_3 = new JButton("\u6DFB\u52A0");
		btnNewButton_3.addActionListener(new ActionListener() {
			public void actionPerformed(ActionEvent e) {
				
				try {
					String inputValue = JOptionPane.showInputDialog("请输入桌子大小：小1  中2  大3");
				
					int i = Integer.parseInt(inputValue);
				
					
					ii=tabl.getTableListSize();
					
					tabl.addTableNumber(ii+1,i);
					Object add[]={new Integer(ii+1),inputValue};
					model5.addRow(add);
					ii++;
					
				} catch (RemoteException e1) {
					// TODO Auto-generated catch block
					e1.printStackTrace();
				} catch (SQLException e1) {
					// TODO Auto-generated catch block
					e1.printStackTrace();
				}
			}
		});
		btnNewButton_3.setBounds(430, 10, 93, 23);
		panel_2.add(btnNewButton_3);
		

		

		JLabel lblNewLabel = new JLabel("New label");
		lblNewLabel.setIcon(new ImageIcon("src/client/images/79ad1ddec6ce9595b6fd48a5.jpg"));
		lblNewLabel.setBounds(0, -25, 671, 479);
		contentPane.add(lblNewLabel);
	}
}
